import 'package:intl/intl.dart';
import 'package:qr_code_app/generated/json/base/json_field.dart';
import 'package:qr_code_app/generated/json/log_entity.g.dart';
import 'dart:convert';
export 'package:qr_code_app/generated/json/log_entity.g.dart';

@JsonSerializable()
class LogEntity {
  String? image = '';
  String? content = '';
  String? timestamp; // 时间戳属性

  String get timeStr {
    DateTime dateTime = DateTime.parse(timestamp ?? '2024-02-29T15:21:31.386011');
    String formattedTimestamp =
        DateFormat('yyyy-MM-dd-HH:mm:ss').format(dateTime);
    return formattedTimestamp;
  }

  LogEntity();

  factory LogEntity.fromJson(Map<String, dynamic> json) =>
      $LogEntityFromJson(json);

  Map<String, dynamic> toJson() => $LogEntityToJson(this);

  @override
  String toString() {
    return jsonEncode(this);
  }
}
